﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class DocumentEntity
    {
        public void ImportList(List<Classes.DocumentEntity> DocumentEntityList)
        {
            var mdb = new MedregDBDataContext();

            var sDocT = new Classes.DocumentType();
            var Doct = new DocumentType();
            Doct.ImportList(sDocT.getDocumentTypeList(DocumentEntityList));


            foreach (Classes.DocumentEntity documentEntity in DocumentEntityList)
            {
                var documentEntity1 = new DocumentEntity
                {
                    Type = documentEntity.Type.ID,
                    Serie = documentEntity.Serie,
                    Number = documentEntity.Number,
                    Issued = documentEntity.Issued,
                    IssueDate = documentEntity.IssueDate,
                    Employee = documentEntity.Employee.ID
                };

                IEnumerable<DocumentEntity> query = (from cr in mdb.DocumentEntity
                                                    where cr.Employee == documentEntity.Employee.ID
                                                    select cr
                                                   ).ToList();
                mdb.DocumentEntity.DeleteAllOnSubmit(query);
                mdb.DocumentEntity.InsertOnSubmit(documentEntity1);
            }
            mdb.SubmitChanges();
        }
    }
}
